package com.wfg.expresscompany.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Optional;

/**
 * @author: 王富贵
 * @description: 发货渠道
 * @createTime: 2023/05/24 22:06
 */
@Getter
@AllArgsConstructor
public enum ShippingChannelsEnum {
    TRAIN("TRAIN", "火车渠道"),
    CART("CART", "汽车渠道"),
    PLANE("PLANE", "飞机渠道");

    private String name;
    private String description;

    private static final HashMap<String, ShippingChannelsEnum> channels = new HashMap<>();

    static {
        ShippingChannelsEnum[] values = values();
        for (ShippingChannelsEnum value : values) {
            // 可以判断是否是装配的
            channels.put(value.getName(), value);
        }
    }

    /**
     * 通过名称获取枚举，未找到默认使用汽车渠道
     *
     * @param name
     * @return
     */
    public static ShippingChannelsEnum getShippingChannelsEnumByName(String name) {
        return Optional.ofNullable(channels.get(name))
                .orElse(CART);
    }
}
